import { defineStore } from 'pinia'
import { computed, reactive, ref } from 'vue'
import { get } from '@/utils/api'

export const useAdminProgramStore = defineStore('adminProgram', () => {
  const tableData = ref<object[]>([])
  const tableLoading = ref<string>('')

  const getData = async () => {
    tableData.value = []
    tableLoading.value = 'loading'
    tableData.value = await get('/api/program/getAll')
    tableLoading.value = ''
  }

  const formData = reactive({
    name: '',
    price: '',
    status: 1,
    cycle: '24',
    description: '',
    imageUrl: '',
    downloadUrl: ''
  })

  const saveDialogVisible = ref<boolean>(false)

  const saveMode = ref<string>('')

  const imageUploadData = ref<object[]>([])

  const downloadUploadData = ref<object[]>([])

  const deleteVisible = ref<boolean>(false)
  const deleteIds = ref<number[]>([])

  const contentLoading = ref<boolean>(true)
  return {
    tableData,
    tableLoading,
    getData,
    saveDialogVisible,
    formData,
    imageUploadData,
    downloadUploadData,
    deleteVisible,
    deleteIds,
    saveMode,
    contentLoading
  }
})
